/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.bar.model.impl;

import com.bar.model.Mailing;
import com.bar.model.MailingModel;
import com.bar.model.MailingSoap;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The base model implementation for the Mailing service. Represents a row in the &quot;mailing_Mailing&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.bar.model.MailingModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link MailingImpl}.
 * </p>
 *
 * @author pgonzalm
 * @see MailingImpl
 * @see com.bar.model.Mailing
 * @see com.bar.model.MailingModel
 * @generated
 */
@JSON(strict = true)
public class MailingModelImpl extends BaseModelImpl<Mailing>
	implements MailingModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a mailing model instance should use the {@link com.bar.model.Mailing} interface instead.
	 */
	public static final String TABLE_NAME = "mailing_Mailing";
	public static final Object[][] TABLE_COLUMNS = {
			{ "mailingId", Types.BIGINT },
			{ "userName", Types.VARCHAR },
			{ "createDate", Types.TIMESTAMP },
			{ "userSurname", Types.VARCHAR },
			{ "mailing", Types.BOOLEAN },
			{ "email", Types.VARCHAR },
			{ "phone", Types.BIGINT }
		};
	public static final String TABLE_SQL_CREATE = "create table mailing_Mailing (mailingId LONG not null primary key,userName VARCHAR(75) null,createDate DATE null,userSurname VARCHAR(75) null,mailing BOOLEAN,email VARCHAR(75) null,phone LONG)";
	public static final String TABLE_SQL_DROP = "drop table mailing_Mailing";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.bar.model.Mailing"), true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.bar.model.Mailing"), true);
	public static final boolean COLUMN_BITMASK_ENABLED = false;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Mailing toModel(MailingSoap soapModel) {
		Mailing model = new MailingImpl();

		model.setMailingId(soapModel.getMailingId());
		model.setUserName(soapModel.getUserName());
		model.setCreateDate(soapModel.getCreateDate());
		model.setUserSurname(soapModel.getUserSurname());
		model.setMailing(soapModel.getMailing());
		model.setEmail(soapModel.getEmail());
		model.setPhone(soapModel.getPhone());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Mailing> toModels(MailingSoap[] soapModels) {
		List<Mailing> models = new ArrayList<Mailing>(soapModels.length);

		for (MailingSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.bar.model.Mailing"));

	public MailingModelImpl() {
	}

	public long getPrimaryKey() {
		return _mailingId;
	}

	public void setPrimaryKey(long primaryKey) {
		setMailingId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_mailingId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Mailing.class;
	}

	public String getModelClassName() {
		return Mailing.class.getName();
	}

	@JSON
	public long getMailingId() {
		return _mailingId;
	}

	public void setMailingId(long mailingId) {
		_mailingId = mailingId;
	}

	@JSON
	public String getUserName() {
		if (_userName == null) {
			return StringPool.BLANK;
		}
		else {
			return _userName;
		}
	}

	public void setUserName(String userName) {
		_userName = userName;
	}

	@JSON
	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	@JSON
	public String getUserSurname() {
		if (_userSurname == null) {
			return StringPool.BLANK;
		}
		else {
			return _userSurname;
		}
	}

	public void setUserSurname(String userSurname) {
		_userSurname = userSurname;
	}

	@JSON
	public boolean getMailing() {
		return _mailing;
	}

	public boolean isMailing() {
		return _mailing;
	}

	public void setMailing(boolean mailing) {
		_mailing = mailing;
	}

	@JSON
	public String getEmail() {
		if (_email == null) {
			return StringPool.BLANK;
		}
		else {
			return _email;
		}
	}

	public void setEmail(String email) {
		_email = email;
	}

	@JSON
	public long getPhone() {
		return _phone;
	}

	public void setPhone(long phone) {
		_phone = phone;
	}

	@Override
	public Mailing toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Mailing)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
					Mailing.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	@Override
	public Object clone() {
		MailingImpl mailingImpl = new MailingImpl();

		mailingImpl.setMailingId(getMailingId());
		mailingImpl.setUserName(getUserName());
		mailingImpl.setCreateDate(getCreateDate());
		mailingImpl.setUserSurname(getUserSurname());
		mailingImpl.setMailing(getMailing());
		mailingImpl.setEmail(getEmail());
		mailingImpl.setPhone(getPhone());

		mailingImpl.resetOriginalValues();

		return mailingImpl;
	}

	public int compareTo(Mailing mailing) {
		long primaryKey = mailing.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Mailing mailing = null;

		try {
			mailing = (Mailing)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = mailing.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
	}

	@Override
	public CacheModel<Mailing> toCacheModel() {
		MailingCacheModel mailingCacheModel = new MailingCacheModel();

		mailingCacheModel.mailingId = getMailingId();

		mailingCacheModel.userName = getUserName();

		String userName = mailingCacheModel.userName;

		if ((userName != null) && (userName.length() == 0)) {
			mailingCacheModel.userName = null;
		}

		Date createDate = getCreateDate();

		if (createDate != null) {
			mailingCacheModel.createDate = createDate.getTime();
		}
		else {
			mailingCacheModel.createDate = Long.MIN_VALUE;
		}

		mailingCacheModel.userSurname = getUserSurname();

		String userSurname = mailingCacheModel.userSurname;

		if ((userSurname != null) && (userSurname.length() == 0)) {
			mailingCacheModel.userSurname = null;
		}

		mailingCacheModel.mailing = getMailing();

		mailingCacheModel.email = getEmail();

		String email = mailingCacheModel.email;

		if ((email != null) && (email.length() == 0)) {
			mailingCacheModel.email = null;
		}

		mailingCacheModel.phone = getPhone();

		return mailingCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(15);

		sb.append("{mailingId=");
		sb.append(getMailingId());
		sb.append(", userName=");
		sb.append(getUserName());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", userSurname=");
		sb.append(getUserSurname());
		sb.append(", mailing=");
		sb.append(getMailing());
		sb.append(", email=");
		sb.append(getEmail());
		sb.append(", phone=");
		sb.append(getPhone());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(25);

		sb.append("<model><model-name>");
		sb.append("com.bar.model.Mailing");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>mailingId</column-name><column-value><![CDATA[");
		sb.append(getMailingId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userName</column-name><column-value><![CDATA[");
		sb.append(getUserName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userSurname</column-name><column-value><![CDATA[");
		sb.append(getUserSurname());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>mailing</column-name><column-value><![CDATA[");
		sb.append(getMailing());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>email</column-name><column-value><![CDATA[");
		sb.append(getEmail());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>phone</column-name><column-value><![CDATA[");
		sb.append(getPhone());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Mailing.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Mailing.class
		};
	private long _mailingId;
	private String _userName;
	private Date _createDate;
	private String _userSurname;
	private boolean _mailing;
	private String _email;
	private long _phone;
	private transient ExpandoBridge _expandoBridge;
	private Mailing _escapedModelProxy;
}